/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "ConnectDlg.h"

#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QComboBox>

#include "ConnectFrame.h"

const QString	c_defaultHost = "127.0.0.1";

const int	c_postgreDefaultPort = 5432;
const int	c_mySqlDefaultPort = 3306;

/**
**/
ConnectDlg::ConnectDlg( QWidget *parent, const Bio::SqlServerSettings &settings, bool create ) : QDialog( parent )
{
	if( create )
		setWindowTitle( tr( "Create a new BioSQL Database" ) );
	else
		setWindowTitle( tr( "Connect to a BioSQL Database" ) );

	initLayout( settings, create );
}

/**
**/
ConnectDlg::~ConnectDlg()
{
}

/**
**/
void ConnectDlg::accept()
{
	QDialog::accept();
}

/**
**/
Bio::SqlServerSettings ConnectDlg::getServerSettings() const
{
	return m_frame->getServerSettings();
}

/**
**/
void ConnectDlg::initLayout( const Bio::SqlServerSettings &settings, bool create )
{
	QPushButton	*btn;
	QVBoxLayout	*layout = new QVBoxLayout;

	setLayout( layout );

	m_frame = new ConnectFrame( this, settings );
	layout->addWidget( m_frame );

	QHBoxLayout	*btnLayout = new QHBoxLayout;

	layout->addLayout( btnLayout );

	btnLayout->setMargin( 0 );
	btnLayout->addStretch( 100 );

	if( create )
		btn = new QPushButton( tr( "Create" ), this );
	else
		btn = new QPushButton( tr( "Connect" ), this );
	connect( btn, SIGNAL(clicked()), this, SLOT(accept()) );
	btnLayout->addWidget( btn );

	btn = new QPushButton( tr( "Cancel" ), this );
	connect( btn, SIGNAL(clicked()), this, SLOT(reject()) );
	btnLayout->addWidget( btn );
}

